package com.woniu.p2p.excelservice;

import com.woniu.p2p.entity.UserCharge;
import com.woniu.p2p.mapper.UserChargeMapper;
import com.woniu.p2p.vo.ImportCharge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author 86152
 * @create 2020/8/15
 * @since 1.0.0
 */
@Service
public class InChargeService {

    @Autowired
    UserChargeMapper userChargeMapper;

    public void readExcel(ImportCharge importCharge) {
        Integer chargeId = importCharge.getChargeId();
        Integer userId = importCharge.getUserId();
        String chargeOrder = importCharge.getChargeOrder();
        Date chargeTime = importCharge.getChargeTime();
        java.sql.Date date = new java.sql.Date(chargeTime.getTime());
        long chargeMoney = importCharge.getChargeMoney();
        String chargeType = importCharge.getChargeType();
        String chargeStatus = importCharge.getChargeStatus();
        String chargeContext = importCharge.getChargeContext();
        UserCharge userCharge = userChargeMapper.selectByPrimaryKey(chargeId);
        if(userCharge==null){
            UserCharge userCharge1 = new UserCharge(chargeOrder, date, chargeMoney, chargeType, chargeStatus, chargeContext, userId);
            userChargeMapper.insert(userCharge1);
        }else {
            UserCharge userCharge1 = new UserCharge(chargeId, chargeOrder, date, chargeMoney, chargeType, chargeStatus, chargeContext, userId);
            userChargeMapper.updateByPrimaryKey(userCharge1);
        }




    }
}
